package com.zyh.listener;

import com.rabbitmq.client.Channel;
import com.zyh.entity.Log;
import com.zyh.service.ILogService;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class LogListener {
    @Autowired
    ILogService logService;
    @RabbitListener(queues = "QA")
    public void receiveD(Message message, Channel channel) throws IOException {
        byte[] body = message.getBody();
        Log log =(Log) SerializationUtils.deserialize(body);
        logService.save(log);
    }
}
